package com.hutao.sso.service.impl.authority;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hutao.sso.dataSource.TargetDataSource;
import com.hutao.sso.mapper.newAuthority.RoleAuthoritysMapper;
import com.hutao.sso.pojo.newAuthority.RoleAuthoritys;
import com.hutao.sso.pojo.newAuthority.Roles;
import com.hutao.sso.service.authority.RoleAuthorityService;
import com.hutao.sso.util.Result;

@Transactional
@Service
public class RoleAuthorityServiceImpl implements RoleAuthorityService{

	@Autowired
	private RoleAuthoritysMapper roleAuthoritysMapper;
	
	
	
	@TargetDataSource(name = "ds1")
	@Override
	public int deleteRoleAuthorityByRoleId(Map<String, Object> params) {
		return roleAuthoritysMapper.deleteRoleAuthorityByRoleId(params);
	}

	@TargetDataSource(name = "ds1")
	@Override
	public Result updateRoleToAllAuthority(String roleId, String medicalMainstayId, List<RoleAuthoritys> roleAuthorityList) {
		Map<String, Object> params = new HashMap<>();
		params.put("roleId", roleId);
		params.put("medicalMainstayId", medicalMainstayId);
		roleAuthoritysMapper.deleteRoleAuthorityByRoleId(params);
		
		if(null != roleAuthorityList && roleAuthorityList.size() > 0) {
			roleAuthoritysMapper.addBatchRoleAuthority(roleAuthorityList);
		}
		
		return new Result(true, "分配权限成功!");
	}

	
	

}
